export async function useAPI<T>(path: string, options?: any): Promise<T> {
  // 封装客户端请求,从 localStorage 中获取token
  const user = useUserStore();

  const config = useRuntimeConfig();
  const headers = options?.headers || {};
  if (user.token) {
    headers.token = user.token;
  } else {
    const token = getToken();
    if (token) {
      headers.token = token.accessToken;
    }
  }
  const response = await $fetch<T>(path, {
    baseURL: config.public.apiBaseUrl,
    ...options,
    headers: {
      ...options?.headers,
      ...headers,
    },
  });
  return response;
}
